import sys
import os
sys.path.append("..")

from TestFlowScheduler import *
from CoreSim.Simulator import *
from Topology.Jellyfish import *
from Routing.K_Shortest_Path import *

inDir = "Input/"
outDir = "Output/"

if __name__ == "__main__":
    
    numHosts = 4
    numLinks = 4
    numSwitches = 8
    link_sh_Bw = 10.0 * Gb
    link_ss_Bw = 10.0 * Gb

    load = 0.6
    randomSeed = 1
    FLOW_LAUNCH_END_TIME = 0.02

    trafficType = 'CDF'
    cdfFileName = "cdf/DCTCP_CDF.txt"
    
    flowsFileName = "flows_%sToRs_%sHosts_%sLinks_%sLoad_%sTime.txt" \
                    %(numSwitches,numHosts,numLinks,load,FLOW_LAUNCH_END_TIME)
    
    compile_cmd = "g++ ./Input/fct.cc -o ./Input/fct -std=c++11"
    os.system(compile_cmd)
    
    run_cmd = "./Input/fct numHosts " + str(numHosts) + " numLinks " + str(numLinks) \
        + " numSwitches " + str(numSwitches) + " link_sh_Bw " + str(link_sh_Bw) \
        + " link_ss_Bw " + str(link_ss_Bw) + " load " + str(load) + " randomSeed " \
        + str(randomSeed) + " cdfFileName " + inDir + cdfFileName + " flowsFileName " \
        + inDir + flowsFileName + " FLOW_LAUNCH_END_TIME " + str(FLOW_LAUNCH_END_TIME) 
    os.system(run_cmd)
    
    sim = Simulator()
    Topo = Jellyfish(numOfHost=numHosts, numOfLink=numLinks, numOfToRs=numSwitches, k=4)
    Topo.CreateTopology()
    sim.AssignTopology(topo=Topo, cap=1.0 * Gb)
    sim.AssignRoutingEngine(Routing=K_Shortest_Path)
    sim.AssignScheduler(FlowScheduler=TestFlowScheduler, args=(trafficType, flowsFileName))
    sim.Run()
    sim.sched.PrintFlows()